var tblTeacher;
$(function () {
    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
        //当切换tab时，强制重新计算列宽
        $.fn.dataTable.tables({visible: true, api: true}).columns.adjust();
    });
    tblTeacher = $('#tbl-teacher').DataTable(buildTeacherOptions());
    trCssEvent(tblTeacher);
    $("#btn-search-teacher").click(teacherSearch);
});

function buildTeacherOptions() {
    var options = {
        "serverSide": true,
        "autoWidth": false,
        "deferRender": true,
        "searching": false,
        "ordering": true,
        "processing": true,
        "scrollX": true,
        "language": {
            "url": "//cdn.datatables.net/plug-ins/1.10.12/i18n/Chinese.json"
        },
        "ajax": {
            "url": '/api/teacher',
            "type": 'get',
            "dataType": 'json',
            data: function (params) {
                params['cid'] = $("#center-id-teacher").val();
                params['name'] = $("#teacher-name").val();
            }
        },
        "columns": [{
            "data": "center_name"
        }, {
            "data": "teacher_name"
        }],
        columnDefs: [{
            "targets": 2,
            "data": "teacher_id",
            "render": function (data, type, row, meta, full) {
                var centerId = data.Center_id;
                return "<a href='Students?teacherId=" + data + "' target='_blank'> 查看老师的学生  </a>"
            }
        }, {"orderable": false, "targets": [0, 1, 2]}
        ],
        "dom": "<'row'<'col-xs-12't>>r<'row'<'col-xs-2 lstyle'l><'col-xs-3'i><'col-xs-6  fright'p>>"
    };
    return options;
}

function teacherSearch() {
    $("#btn-search-teacher").attr("disabled", "disabled");
    tblTeacher.ajax.reload(function () {
        $("#btn-search-teacher").removeAttr("disabled");
    });
}


